<include file='Admin/Tpl/Public/nav.html' />
<style>
  a{cursor:pointer;}
</style>
<div class="sidebar-right-heading">
      <ul class="nav nav-tabs square nav-justified">
            <li class="active"><a href="#online-user-sidebar" data-toggle="tab"><i class="fa fa-comments"></i></a></li>
            <li><a href="#notification-sidebar" data-toggle="tab"><i class="fa fa-bell"></i></a></li>
            <li><a href="#task-sidebar" data-toggle="tab"><i class="fa fa-tasks"></i></a></li>
            <li><a href="#setting-sidebar" data-toggle="tab"><i class="fa fa-cogs"></i></a></li>
      </ul>
</div><!-- /.sidebar-right-heading -->
<div class="page-content">
      <div class="container-fluid">
   		<h1 class="page-heading">Team In <small>地址管理</small></h1>            
            <h5 class="small-title">地址列表</h5>
            <a href="__URL__/forAct" class="btn btn-success">添加新地址</a>
            <ul class="ul_box">
                 <li style="width:30%">
                      <div class="table-responsive div1 div_search">                        
                         <table class="table table-th-block table-hover">                                
                               <thead>
                                     <tr>                                        
                                          <th colspan=2>地区城市</th>
                                     </tr>                           
                               </thead>
                               <tbody>
                                <foreach name="local" item="value">                                 
                                    <tr>
                                        <td class="city" name="{$value.local_id}">{$value.local_name}</td>
                                        <td style="width:100px;text-align:center" name="{$value.local_id}">
                                        <a class="savec">修改</a>/
                                        <a href="javascript:void(0)" onclick="to_del(1,{$value.local_id})">删除</a>
                                        </td>
                                    </tr>
                                </foreach>
                               </tbody>                                  
                         </table>
                         <ul class="pagination success">{$rs.show}</ul>
                      </div>
                 </li>
                
                <div id="build">
                     <li style="width:30%">
                          <div class="table-responsive div_building div_search">                        
                             <table class="table table-th-block table-hover">                                
                                   <thead>
                                         <tr>                                        
                                              <th colspan="2">楼座列表</th>
                                         </tr>                           
                                   </thead>
                                   <tbody>
                                      <foreach name="building" item="value">                                 
                                              <tr>
                                                  <td class="build" name="{$value.building_id}">{$value.building_name}</td>
                                                  <td style="width:100px;text-align:center" name="{$value.building_id}" >
                                                  	<a class="saveb" name="{$value.local_id}">修改</a>/
                                                    <a href="javascript:void(0)" onclick="to_del(2,{$value.building_id})">删除</a></td>
                                              </tr>
                                         </foreach>
                                   </tbody>                                  
                             </table>
                             <ul class="pagination success">{$rs.show}</ul>
                          </div>
                     </li>
                    <div id="floor">
                         <li style="width:30%">
                             <div class="table-responsive div1 div_search">                          
                                  <table class="table table-th-block table-hover">                                
                                     <thead>
                                           <tr>                                        
                                                <th colspan=2>楼层列表</th>
                                           </tr>                           
                                     </thead>
                                     <tbody>
                                        <foreach name="floor" item="value">                                 
                                            <tr>
                                                <td class="{$value.floor_id}">{$value.floor_name}</td>
                                                <td style="width:100px;text-align:center" name="{$value.floor_id}" class="">
                                                    <a class="savef" name="{$value.building_id}">修改</a>/
                                                    <a href="javascript:void(0)" onclick="to_del(3,{$value.floor_id})">删除</a></td>
                                            </tr>
                                        </foreach>
                                     </tbody>
                                  </table>
                                  <ul class="pagination success">{$rs.show}</ul>
                             </div>
                          </li>
                    </div>
                 </div>

            </ul>
      </div>
</div>
<div class="back" style="display:none;position:absolute;top:0;bottom:0;opacity:0.3;width:100%;background:black;"></div>
<!--城市修改开始-->
<div class="add_data add_city the-box" style="display:none;border-radius:3px;position:absolute;z-index:100;left:30%;top:30%;" >
      <div class="sub sub_remove" style="float:right;font-size:25px;margin-top:-20px;margin-right:-5px;">x</div>
      <h4 id="title_name">城市修改:</h4>
      <div class="box_city">
        <div class="input">
              <input type="hidden" name="local_id" id="local_id" value="">
              <input style="margin-bottom:5px" class="local_name form-control must" id="local" type="text" name="local_name" value="" />
        </div>  
        <br />
        <div style="float:left;margin-right:5px;" class="sub sub_add btn btn-info">修改</div>
        <div style="float:left;" class="sub sub_remove btn btn-danger">取消</div>
      </div>
      <div class="result" style="display:none"></div>
</div>
<!--城市修改结束-->
<!--楼座修改开始-->
<div class="add_data update_build the-box" style="display:none;border-radius:3px;position:absolute;z-index:100;left:50%;top:30%;" >
      <div class="sub sub_remove" style="float:right;font-size:25px;margin-top:-20px;margin-right:-5px;">x</div>
      <h4 id="title_name">楼座修改:</h4>
      <div class="box_build">
        <div class="input">
              <input type="hidden" name="building_id" id="building_id" value="">
              城市选择：
              <select class="form-control city_check" tabindex="2" name="local_id" id="select">
                  <foreach name="local" item="value">
                    <option value="{$value.local_id}">{$value.local_name}</option>
                  </foreach>                            
              </select>
              楼座名称：
              <input style="margin-bottom:5px" class="form-control building" id="build_name" type="text" name="building_name" value="" />
        </div>  
        <br />
        <div style="float:left;margin-right:5px;" class="sub update_building btn btn-info">修改</div>
        <div style="float:left;" class="sub sub_remove btn btn-danger">取消</div>
      </div>
      <div class="result_build" style="display:none"></div>
</div>
<!--楼座修改结束-->

<!--楼层修改开始-->
<div class="update_floor the-box" style="display:none;border-radius:3px;position:absolute;z-index:100;left:70%;top:20%;" >
      <div class="sub sub_remove" style="float:right;font-size:25px;margin-top:-20px;margin-right:-5px;">x</div>
      <h4 id="title_name">楼层修改:</h4>
      <div class="box_floor">
        <div class="input">
              <input type="hidden" name="floor_id" id="floor_id" value="">
              城市选择：
              <select class="form-control city_check local_floor" name="floor" tabindex="2" name="local_id" id="select" onchange="selChange(this)">
                  <foreach name="local" item="value">
                    <option value="{$value.local_id}">{$value.local_name}</option>
                  </foreach>                            
              </select>
              楼座选择：
              <select class="form-control build_check build_floor" tabindex="2" name="build_id" id="select2">
                  <foreach name="building" item="value">
                    <option value="{$value.building_id}">{$value.building_name}</option>
                  </foreach>                            
              </select>
              楼层名称：
              <input style="margin-bottom:5px" class="form-control floor" id="floor_name" type="text" name="floor_name" value="" />
        </div>  
        <br />
        <div style="float:left;margin-right:5px;" class="sub save_floor btn btn-info">修改</div>
        <div style="float:left;" class="sub sub_remove btn btn-danger">取消</div>
      </div>
      <div class="result_floor" style="display:none"></div>
</div>
<!--楼层修改结束-->             
</body>
<script>
function to_del($type,$id)
{
	$.get(
		'__URL__/delAct?type='+$type+'&id='+$id,function(data){
			if(data.state==0)
				window.location='__SELF__';	
		},'json'
	);
}
//城市选择
var city_id = 1;
  $(".city").eq(0).css({background:"#8CC152"});
  $(".build").eq(0).css({background:"#8CC152"});
  $(".city").click(function(){
		var local_id = $(this).attr("name");
		city_id = local_id;
		$(".city").css({background:""});
		$(this).css({background:"#8CC152"});     
		$.ajax({
			url:"__URL__/building",
			data:{"local_id":local_id},
			type:"post",
			success:function(data){
				$("#build").html(data);
			}
		});
  });
//楼座选择
$(".build").click(function(){    
     var building_id = $(this).attr("name");
     $(".build").css({background:""});
     $(this).css({background:"#8CC152"});    
      $.ajax({
      url:"__URL__/floor",
      data:{"building_id":building_id},
      type:"post",
      success:function(data){
        $("#floor").html(data);
      }
    });
  });

//城市修改
$(".savec").click(function(){
  var local_id = $(this).parent().attr("name");
  var local_name = $(this).parent().prev().text();
  $("#local_id").val(local_id);
  $("#local").val(local_name);
  $(".back").css({display:"block"});
  $(".add_city").css({display:"block"});  
});

$(".sub_add").click(function(){
    var local_id = $("#local_id").val();
    var local_name = $("#local").val();
    $.ajax({
      url:"__URL__/savec",
      data:{"local_id":local_id,"local_name":local_name},
      type:"post",
      success:function(data){
          $(".box_city").css({display:"none"});
          $(".result").html(data);
          $(".result").css({display:"block"});                  
      }
    });
});

$(".sub_remove").click(function(){
      $(".back").css({display:"none"});
      $(".the-box").css({display:"none"});

});

//楼座修改
$(".saveb").click(function(){
      var building_id = $(this).parent().attr("name");
      var building_name = $(this).parent().prev().text();
      var local_id = $(this).attr("name");        
      $(".city_check option[value="+local_id+"]").attr("selected","selected");
      $("#building_id").val(building_id);
      $(".building").val(building_name);     
      $(".back").css({display:"block"});
      $(".update_build").css({display:"block"});
});

$(".update_building").click(function(){
    var local_id = $(".city_check option:selected").val();
    var build_id = $("#building_id").val();
    var build_name = $("#build_name[name='building_name']").val(); 
    
    $.ajax({
      url:"__URL__/saveb",
      data:{"building_id":build_id,"local_id":local_id,"building_name":build_name},
      type:"post",
      success:function(data){
          $(".box_build").css({display:"none"});
          $(".result_build").html(data);
          $(".result_build").css({display:"block"});                  
      }
    });
});

//楼层修改
$(".savef").click(function(){
      var local_id = city_id;      
      var floor_id =$(this).parent().prev().attr("class");
      var floor_name =$(this).parent().prev().text();
      var building_id = $(this).attr("name");      
      $.ajax({
        url:"__URL__/build_floor",
        data:{"local_id":local_id},
        type:"post",
        success:function(data){
          $(".build_floor").html(data);
          $(".build_floor option[value="+building_id+"]").attr("selected","selected");
        }
      }); 
      $(".city_check option[value="+local_id+"]").attr("selected","selected");
      
      $("#floor_id").val(floor_id);
      $("#floor_name").val(floor_name);     
      $(".back").css({display:"block"});
      $(".update_floor").css({display:"block"});
});
//楼层修改城市选择
function selChange(obj){
      var local_id = obj.options[obj.selectedIndex].value;
      $.ajax({
        url:"__URL__/build_floor",
        data:{"local_id":local_id},
        type:"post",
        success:function(data){
          $(".build_floor").html(data);
        }
      });
}
$(".save_floor").click(function(){
    var local_id= $(".city_check option:selected").val();
    var building_id= $(".build_check option:selected").val();
    var floor_id= $("#floor_id").val();
    var floor_name=$("#floor_name").val();
   
    $.ajax({
      url:"__URL__/savef",
      data:{"local_id":local_id,"building_id":building_id,"floor_id":floor_id,"floor_name":floor_name},
      type:"post",
      success:function(data){        
          $(".box_floor").css({display:"none"});
          $(".result_floor").html(data);
          $(".result_floor").css({display:"block"});
      }
    });
});
</script>
</html>